package cn.tedu.controller;


import cn.tedu.entity.MenusEntity;
import cn.tedu.service.MenuService;
import cn.tedu.vo.JsonResult;
import cn.tedu.vo.Node;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;
    @RequestMapping("/doFindObjects")
    public JsonResult doFindObjects(){
        List<MenusEntity> list = menuService.findObjects();
        return new JsonResult(list);
    }
    @PostMapping("/doSaveObject")
    public JsonResult doSaveMenu( MenusEntity menusEntity){
        //Subject subject = SecurityUtils.getSubject();
        //UsersEntity principal = (UsersEntity)subject.getPrincipal();
        menusEntity.setCreatedUser("admin").setModifiedUser("admin").setCreatedTime(new Date()).setModifiedTime(new Date());
        menuService.save(menusEntity);
        return new JsonResult("保存成功!");
    }
    @PostMapping("/doUpdateObject")
    public JsonResult doUpdateMenu( MenusEntity menusEntity){
        menuService.updateById(menusEntity);
        return new JsonResult("修改成功!");
    }
    @RequestMapping("/doFindZtreeMenuNodes")
    public JsonResult doFindZtreeMenuNodes(){
        List<Node> list = menuService.doFindZtreeMenuNodes();
        return new JsonResult(list);
    }
    @RequestMapping("/doDeleteObject")
    public JsonResult doDeleteById(String id){
        menuService.removeById(id);
        return new JsonResult("删除成功!");
    }

}
